<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="创建时间" :style="{ fontWeight: '800' }">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="carPackageAuditList"
      :header-row-style="{ fontWeight: '800' }"
      style="width: 1200px"
    >
      <el-table-column
        label="套餐名称"
        align="center"
        prop="serviceItemName"
      />
      <el-table-column
        label="套餐价格"
        align="center"
        prop="serviceItemPrice"
      />
      <el-table-column
        label="套餐备注"
        align="center"
        prop="serviceItemInfo"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="创建者"
        align="center"
        prop="creatorNickName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="备注"
        align="center"
        prop="info"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="已办任务名称"
        align="center"
        prop="doneTaskName"
        :show-overflow-tooltip="true"
        width="100px"
      />
      <el-table-column
        label="任务完成时间"
        align="center"
        prop="doneTaskDateTime"
        :show-overflow-tooltip="true"
        width="100px"
      />
      <el-table-column
        label="审核状态"
        align="center"
        prop="status"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.si_package_audit_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="当前审核人"
        align="center"
        :show-overflow-tooltip="true"
      >
        <div slot-scope="scope">
          {{ scope.row.status === 1 ? scope.row.candidateUserList : '无'}}
        </div>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="200px"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-check"
            @click="handleHistory(scope.row)"
            v-hasPermi="['workflow:carPackageAudit:history']"
            >审批历史</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="handleProgressImg(scope.row)"
            v-hasPermi="['workflow:carPackageAudit:processImg']"
            >进度查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


    <!-- 审批历史按钮对话框 -->
    <el-dialog
      :title="historyTitle"
      :visible.sync="historyOpen"
      width="1000px"
      append-to-body
    >
      <el-table
        v-loading="loading"
        :data="historyList"
        :header-row-style="{ fontWeight: '800' }"
      >
        <el-table-column
          label="任务名称"
          align="center"
          prop="activityName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="开始时间"
          align="center"
          prop="startTime"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="结束时间"
          align="center"
          prop="endTime"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="耗时"
          align="center"
          prop="datePoor"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="审批人"
          align="center"
          prop="assignee"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="审批意见"
          align="center"
          prop="message"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="撤销理由"
          align="center"
          prop="reason"
          :show-overflow-tooltip="true"
        />
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关闭</el-button>
      </div>
    </el-dialog>

    <!-- 进度查看 -->
    <el-dialog
      :title="processImgTitle"
      :visible.sync="processImgOpen"
      width="1300px"
      append-to-body
    >
      <div v-html="processImg"></div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listDoneCarPackageAudit,
  readProcessImg,
  historyProcess,
} from "@/api/workflow/doneTask";

export default {
  name: "CarPackageAudit",
  dicts: ["si_package_audit_status", "si_service_catalog"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 套餐信息表格数据
      carPackageAuditList: [],
      // 审批历史弹出层标题
      historyTitle: "",
      // 审批历史是否显示弹出层
      historyOpen: false,
      // 审批历史记录
      historyList: [],
      // 进度查看弹出层标题
      processImgTitle: "",
      // 进度查看是否显示弹出层
      processImgOpen: false,
      // 审核状态时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createTime: null,
      },
      // 表单校验
      rules: {},
      //查看流程进度svg图片
      processImg: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 审批历史 */
    handleHistory(row) {
      this.historyOpen = true;
      this.historyTitle = "审批历史";
      historyProcess(row.instanceId).then(
        (res) => (this.historyList = res.rows)
      );
    },
    /** 进度查看 */
    handleProgressImg(row) {
      readProcessImg(row.id).then((res) => {
        this.processImgOpen = true;
        this.processImgTitle = "进度查看";
        this.processImg = res;
      });
    },

    /** 查询我的已办任务列表 */
    getList() {
      this.loading = true;
      if (null != this.daterangeCreateTime && "" != this.daterangeCreateTime) {
        this.$set(
          this.queryParams,
          "beginCreateTime",
          this.daterangeCreateTime[0]
        );
        this.$set(
          this.queryParams,
          "endCreateTime",
          this.daterangeCreateTime[1]
        );
      } else {
        (this.queryParams.beginCreateTime = null),
          (this.queryParams.endCreateTime = null);
      }
      listDoneCarPackageAudit(this.queryParams).then((response) => {
        this.carPackageAuditList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.historyOpen = false;
      this.processImgOpen = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      (this.queryParams.beginCreateTime = null),
        (this.queryParams.endCreateTime = null),
        this.resetForm("queryForm");
      this.handleQuery();
    }
  },
};
</script>
